//
//  AppPayCell.swift
//  letuofu
//
//  Created by WH-JS on 2020/3/16.
//  Copyright © 2020 WH-JS. All rights reserved.
//

import UIKit

class AppPayCell: UICollectionViewCell {
    let titleLab = UILabel()
    let subLab = UILabel()
    
    var celldata : [String: Any?]? {
        didSet{
            loadData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override var isSelected: Bool {
        didSet{
            if isSelected {
                titleLab.textColor = .white
                subLab.textColor = .white

                self.backgroundColor = .orange
            }
            else {
                titleLab.textColor = .orange
                subLab.textColor = .orange

                self.backgroundColor = .white
            }
        }
    }
    
    func initView(){
        self.drawLabel(label: titleLab, text: "", fontSize: 20, textColor: .orange) { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-10)
        }
        titleLab.textAlignment = .center
        self.drawLabel(label: subLab, text: "", fontSize: 14, textColor: .orange) { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(10)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
        }
        subLab.textAlignment = .center
        subLab.adjustsFontSizeToFitWidth = true
        subLab.minimumScaleFactor =  0.5
        self.backgroundColor = .white
        self.layer.borderWidth = 5
        self.layer.borderColor = UIColor.orange.cgColor
        self.layer.cornerRadius = 8
    }
    
    func loadData() {
        titleLab.text = celldata?.getString("title")
        subLab.text = celldata?.getString("subtitle")
    }
}
